package bishi.day07_4_25;

import java.util.Scanner;

/**
 * @author huweilong
 * @date 2022/04/25 10:59
 **/
public class Fibonacci {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()) {
            int n = sc.nextInt();
            int a = 0;
            int b = 1;
            while(true) {
                int temp =a + b;
                a = b;
                b = temp;
                if(a <= n && b >= n) {
                    break;
                }
            }
            System.out.println(Math.min(Math.abs(a - n),Math.abs(b - n)));
        }
    }
}